package com.hns.can.mainte.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.master.entity.CommEltMhyOprtInfoEntity;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 电机Service
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Service
public class EltMhyService extends CommonService {
	
    @Autowired
    private FillCodeDscValue codeDscValue;

    private void fillInfoValue(List list) throws Exception {
        Map<String, String> map = new HashMap<String, String>();
        map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo1 = new FillParamsVo("lineId", map);
        map = new HashMap<String, String>();
        map.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo2 = new FillParamsVo("organId", map);
        codeDscValue.fillInfoValue(list, new String[]{GlobalConst.CACHE_KEY_BASE_LINE_INFO, GlobalConst.CACHE_KEY_BASE_ORGAN}, vo1, vo2);
    }
    
    /**
     * 分页查询电机运行分析数据
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @SuppressWarnings("static-access")
    @Transactional
    @LeftOrgAnnotation()
    public Pagination getEltMhyManagePage(CommonParamsVo params) throws Exception {
        Pagination page = this.myBatisPage("eltMhy.getEltMhyCnt", "eltMhy.getEltMhyPageList", params,CommEltMhyOprtInfoEntity.class);
        List list = page.getData();
        fillInfoValue(list);
        page.setData(list);
        return page;
    }

    /**
     * 查询电机运行分析数据（导出使用）
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
	@SuppressWarnings({"unchecked", "static-access" })
    @Transactional
    @LeftOrgAnnotation()
    public List<BaseEntity> getEltMhyList(CommonParamsVo params) throws Exception {
        List<BaseEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("eltMhy.getEltMhyList", params), CommEltMhyOprtInfoEntity.class);
        fillInfoValue(list);
        Map<String,String> map = new HashMap<String,String>();
        map.put("hybridReadySt", "HYBR0000");
        codeDscValue.fillCodeDscValue(list, map);
        return list;
    }
	
}
